package site.hackway;

import my.init;
import my.mvc.ActionCallback;
import my.mvc.RequestContext;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import java.io.IOException;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.util.Properties;

/**
 * Created by hackway on 2016/5/16.
 */
public class Init implements ActionCallback {
    @Override
    public void beforeCall(Method method, RequestContext ctx) throws Exception {

    }

    @Override
    public void afterCall(Method method, RequestContext ctx) throws Exception {

    }

    public static void main(String[] args) {
        Properties properties = new Properties();
        try {
            properties.load(Init.class.getResourceAsStream("velocity.properties"));
            Velocity.init(properties);
            VelocityContext context = new VelocityContext();

            context.put("name", "Velocity");
            context.put("project", "Jakarta");

        /* lets render a template 相对项目路径 */
            Template template = Velocity.getTemplate("/view/header.vm");

            StringWriter writer = new StringWriter();

        /* lets make our own string to render */
            template.merge(context, writer);
            System.out.println(writer);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
